<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/26
 * Time: 14:45
 */

namespace app\api\controller\v1;


use app\api\validate\IDMustBePostiveInt;
use app\api\validate\IdsCollection;
use app\lib\exception\NotFoundException;
use think\Controller;
use app\api\model\Theme as ThemeModel;

class Theme extends Controller
{

    /**
     * @param string $ids
     * @return false|\PDOStatement|string|\think\Collection
     * @throws NotFoundException
     * @url /theme?ids=1,2,3
     */
    public function getSimpleList($ids=''){
        (new IdsCollection())->goCheck();

        $ids = explode(',',$ids);
        $result = ThemeModel::with('topicImg,headImg')->select($ids);

        if(!$result){
            throw new NotFoundException();
        }

        return $result;
    }

    /**
     * @param $id
     * @return string
     * @url = @url /theme/:id
     */
    public function getComplexOne($id){

        (new IDMustBePostiveInt())->goCheck();

        $theme = ThemeModel::getThemeProducts($id);

        if(!$theme){
            throw new NotFoundException();
        }

        return $theme;
    }

}